<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_link_info(row)" size="small">关联数据</el-button>
    </template>
  </list_url>
</template>
<script>
export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    if(in_right_admin('LogDividend/add_money') && this.$get('this_index')==1) btns['虚拟业绩'] = function(){ app.iframe('edit_money') }

    let log_dividend_id = this.$get('id');
    if (!log_dividend_id){
      if (this.__iframe){
        iframe.remove('index_money');
      }else {
        this.$router.push('index');
      }
    }

    let status_config = this.admin_config('status_alias_map.log_dividend_money.status');
    status_config = this.decode_config(status_config);
    status_config.unshift({content:"全部", value:""})
    let forms_config = {
      log_dividend_id: {name:'where[log_dividend_id][eq]', label:'分红ID', type:'hidden', value:log_dividend_id},
      status: {name:'where[status][eq]', label:'状态', type:'radio', button:true, config:status_config, value:""},
    };
    let list_cols = {
      id:{name:'id', label:'ID', width:'65px', fixed:'left'},
      phone:{name:'phone', label:'电话号码', width:'120px'},
      nickname:{name:'nickname', label:'昵称', width:'120px'},
      pay_money: {name:'pay_money', label:'支付金额', width:'80px'},
      dividend_ratio: {name:'dividend_ratio', label:'分红比例', width:'80px'},
      dividend_money: {name:'dividend_money', label:'分红金额', width:'80px'},
      note: {name:'note', label:'详情'},
      status:{name:'status', label:'状态', width: '60px', type:'select_one',config:status_config},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    if (!this.admin_config('this_tenant.id')){
      list_cols['tenant_id'] = {name:'tenant_id', label:'租户', width:'65px', fixed:'right'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/log_dividend/'+(is_del?'recycle':'list_money'),
        title: "分红池列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          list.forEach(row=>{
            row.phone = row.phone || '无';
            row.nickname = row.nickname || '无';
          })
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
      sharing_receiver_map: {},
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('OrderSharing/edit') && ~[0,row.tenant_id].indexOf(this.admin_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      this.iframe('edit?'+s94Mjs.param_encode(param))
    },
    to_link_info(row){
      if (!row.link_table || !row.link_id) return;
      let is_order = row.link_table.match(/^(.+)_order/);
      if (is_order){
        this.iframe('/order/edit?id='+row.link_id+'&model_name='+is_order[1]);
      }else {
        this.$message('无关联数据');
      }
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;


  }
}
</script>
